home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / rpcecho / RCS / rpcecho.c,v < prev   
Text File  |  1990-09-27  |  8KB  |  344 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.09.27.18.15.38;  author brent;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.10.03.11.10.23;  author brent;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Program to exercise the RPC system.
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @Mary checking this in for Brent.
  28. @
  29. text
  30. @/*
  31.  * rpcecho - do a series of rpc Echoes to a server for testing.
  32.  */
  33. #include "sprite.h"
  34. #include "fs.h"
  35. #include "fsCmd.h"
  36. #include "stdio.h"
  37. #include "rpc.h"
  38. #include "netEther.h"
  39. #include "kernel/rpcPacket.h"
  40. #include "proc.h"
  41. #include "option.h"
  42. #include "host.h"
  43. #include "sysStats.h"
  44.  
  45. /*
  46.  * Default values for parameters
  47.  */
  48. char *server = NULL;
  49. int numEchoes = 100;
  50. #define DATASIZE    32
  51. int size = DATASIZE;
  52. int maxSize = 16 * 1024;
  53. int numReps = 10;
  54.  
  55. #define BYTES_PER_FRAG    (NET_ETHER_MAX_BYTES - sizeof(RpcHdr))
  56. /*
  57.  * Buffer areas for data sent and received
  58.  */
  59. #define BUFSIZE (16 * 1024)
  60. char inDataBuffer[BUFSIZE];
  61. char outDataBuffer[BUFSIZE];
  62.  
  63. /*
  64.  * Server flags set by command line arguments
  65.  */
  66. Boolean doEchoes = TRUE;
  67. Boolean doSends = FALSE;
  68. Boolean fastCS = FALSE;
  69. Boolean trace = FALSE;
  70. Boolean allSizes = FALSE;
  71. Boolean reverse = FALSE;
  72.  
  73.  
  74. Option optionArray[] = {
  75.     OPT_INT, "n", (Address)&numEchoes, "Number of RPCs to do",
  76.     OPT_INT, "d", (Address)&size, "Datasize to transmit",
  77.     OPT_TRUE, "D", (Address)&allSizes, "Do tests at all sizes",
  78.     OPT_TRUE, "R", (Address)&reverse, "Do all sizes, high-to-low",
  79.     OPT_TRUE, "e", (Address)&doEchoes, "Echo off RPC server (default)",
  80.     OPT_INT, "r", (Address)&numReps, "Number of reps for each size",
  81.     OPT_TRUE, "s", (Address)&doSends, "Send instead of Echo",
  82.     OPT_TRUE, "t", (Address)&trace, "Trace records taken (runs slower)",
  83.     OPT_TRUE, "c", (Address)&fastCS, "High priority",
  84.     OPT_STRING, "h", (Address)&server, "name of target host",
  85. };
  86. int numOptions = sizeof(optionArray) / sizeof(Option);
  87.  
  88. main(argc, argv)
  89.     int argc;
  90.     char *argv[];
  91. {
  92.     int error;
  93.     int openFileId;
  94.     char c;
  95.     char *fileName;
  96.     Time deltaTime;
  97.     Boolean oldTrace;
  98.     int command;
  99.     Host_Entry *entryPtr;
  100.     int serverID;
  101.     int myID;
  102.     Rpc_CltStat cltStat;
  103.  
  104.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  105.  
  106.     if (server == NULL) {
  107.     fprintf(stderr, "Need a target host (-h hostname)\n");
  108.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  109.     exit(1);
  110.     }
  111.     if (size < 0) {
  112.     size = 0;
  113.     } else if (size > 16384) {
  114.     size = 16384;
  115.     }
  116.  
  117.     entryPtr = Host_ByName(server);
  118.     if (entryPtr == (Host_Entry *) NULL) {
  119.     fprintf(stderr, "Unable to get host number for host '%s'\n",
  120.                server);
  121.     exit(1);
  122.     }
  123.     serverID = entryPtr->id;
  124.  
  125.     if (doSends) {
  126.     printf("Rpc Send Test: N = %d, Host = %s (%d),",
  127.             numEchoes, server, serverID);
  128.     } else {
  129.     printf("Rpc Send Test: N = %d, Host = %s (%d),",
  130.             numEchoes, server, serverID);
  131.     }
  132.     if (reverse) allSizes = TRUE;
  133.     if (allSizes) {
  134.     printf(" all sizes\n");
  135.     } else {
  136.         printf(" size = %d\n", size);
  137.     }
  138.  
  139.     if (fastCS) {
  140.     error = Proc_SetPriority(PROC_MY_PID, PROC_NO_INTR_PRIORITY, FALSE);
  141.     if (error != SUCCESS) {
  142.         perror( "");
  143.     }
  144.     }
  145.         
  146.  
  147.     if (trace) {
  148.     oldTrace = TRUE;
  149.     (void) Fs_Command(FS_SET_RPC_TRACING, sizeof(int), &oldTrace);
  150.     }
  151.     command = doSends ? TEST_RPC_SEND : TEST_RPC_ECHO ;
  152.  
  153.     if (!allSizes) {
  154.     error = DoTest(command, serverID, numEchoes, size,
  155.             inDataBuffer, outDataBuffer, &deltaTime, &cltStat);
  156.     printf("N = %d Size = ", numEchoes);
  157.     PrintTime(size, &deltaTime, &cltStat);
  158.     if (error != 0) {
  159.         printf("status %x\n", error);
  160.     }
  161.     } else {
  162.     int extra;
  163.     error = DoTest(command, serverID, 10, 32,
  164.             inDataBuffer, outDataBuffer, &deltaTime, &cltStat);
  165.     if (error != SUCCESS) {
  166.         fprintf(stderr, "RPC test failed: %x\n", error);
  167.         exit(error);
  168.     }
  169.     if (size != DATASIZE) {
  170.         maxSize = size;
  171.     }
  172.     if (! reverse) {
  173.         for (size = 0; size < maxSize ; size += BYTES_PER_FRAG) {
  174.         DoIt(command, serverID, numEchoes, size);
  175.         for (extra = 400 ; (extra < BYTES_PER_FRAG) &&
  176.             (size+extra < maxSize) ; extra += 400) {
  177.             DoIt(command, serverID, numEchoes, size+extra);
  178.         }
  179.         }
  180.     } else {
  181.         size = (maxSize / BYTES_PER_FRAG) * BYTES_PER_FRAG;
  182.         for ( ; size >= 0 ; size -= BYTES_PER_FRAG) {
  183.         DoIt(command, serverID, numEchoes, size);
  184.         for (extra = 250 ; (extra < BYTES_PER_FRAG) &&
  185.             (size-extra >= 0) ; extra += 400) {
  186.             DoIt(command, serverID, numEchoes, size-extra);
  187.         }
  188.         }
  189.     }
  190.     }
  191.     if (trace) {
  192.     (void) Fs_Command(FS_SET_RPC_TRACING, sizeof(int), &oldTrace);
  193.     }
  194.  
  195.     exit(error);
  196. }
  197.  
  198. DoIt(command, serverID, numEchoes, size)
  199.     int command, serverID, numEchoes, size;
  200. {
  201.     Time deltaTime;
  202.     register int i;
  203.     ReturnStatus error;
  204.     Rpc_CltStat cltStat;
  205.  
  206.     fprintf(stderr, "%5d bytes\n", size);
  207.     for (i=0 ; i<numReps ; i++) {
  208.     error = DoTest(command, serverID, numEchoes, size ,
  209.         inDataBuffer, outDataBuffer, &deltaTime, &cltStat);
  210.     PrintTime(size, &deltaTime, &cltStat);
  211.     if (error != SUCCESS) {
  212.         perror( "RPC test failed:");
  213.         exit(error);
  214.     }
  215.     }
  216. }
  217.  
  218. PrintTime(size, timePtr, cltStatPtr)
  219.     int size;
  220.     Time *timePtr;
  221.     Rpc_CltStat *cltStatPtr;
  222. {
  223.     printf("%d\t%d.%06d ", size, timePtr->seconds, timePtr->microseconds);
  224.     if (cltStatPtr->timeouts > 0) {
  225.     printf("timeouts %d ", cltStatPtr->timeouts);
  226.     }
  227.     if (cltStatPtr->resends > 0) {
  228.     printf("resends %d ", cltStatPtr->resends);
  229.     }
  230.     if (cltStatPtr->acks > 0) {
  231.     printf("acks %d ", cltStatPtr->acks);
  232.     }
  233.     printf("\n");
  234.     fflush(stdout);
  235. }
  236.  
  237. ReturnStatus
  238. DoTest(command, serverID, numEchoes, size, inDataBuffer, outDataBuffer,
  239.     timePtr, cltStatPtr)
  240.     int command;
  241.     int serverID;
  242.     int numEchoes;
  243.     int size;
  244.     Address inDataBuffer;
  245.     Address outDataBuffer;
  246.     Time *timePtr;
  247.     Rpc_CltStat *cltStatPtr;
  248. {
  249.     Rpc_EchoArgs echoArgs;
  250.     ReturnStatus error;
  251.     Rpc_CltStat startCltStat;
  252.  
  253.     if (Sys_Stats(SYS_RPC_CLT_STATS, TRUE, &startCltStat) != SUCCESS) {
  254.     bzero((char *)&startCltStat, sizeof(Rpc_CltStat));
  255.     }
  256.  
  257.     echoArgs.serverID = serverID;
  258.     echoArgs.n = numEchoes;
  259.     echoArgs.size = size;
  260.     echoArgs.inDataPtr = inDataBuffer;
  261.     echoArgs.outDataPtr = outDataBuffer;
  262.     echoArgs.deltaTimePtr = timePtr;
  263.     error = Test_Rpc(command, &echoArgs);
  264.  
  265.     if (Sys_Stats(SYS_RPC_CLT_STATS, TRUE, cltStatPtr) != SUCCESS) {
  266.     bzero((char *)cltStatPtr, sizeof(Rpc_CltStat));
  267.     } else {
  268.     register int *beforePtr, *afterPtr;
  269.     register int wordCount = 0;
  270.  
  271.     for (wordCount = 0,
  272.          beforePtr = (int *)&startCltStat, afterPtr = (int *)cltStatPtr;
  273.          wordCount < sizeof(Rpc_CltStat) / sizeof(int) ;
  274.          wordCount++, beforePtr++, afterPtr++) {
  275.         *afterPtr = *afterPtr - *beforePtr;
  276.     }
  277.     }
  278.  
  279.     return(error);
  280. }
  281. @
  282.  
  283.  
  284. 1.1
  285. log
  286. @Initial revision
  287. @
  288. text
  289. @d14 1
  290. d42 1
  291. d49 1
  292. d73 1
  293. a95 13
  294. #ifdef NOTDEF
  295.     error = Sys_GetMachineInfo((int *) NULL, (int *) NULL, &myID);
  296.     if (error != SUCCESS) {
  297.     perror( "Sys_GetMachineInfo");
  298.     exit(error);
  299.     }
  300.     if (myID == serverID) {
  301.     fprintf(stderr, "Unable to send RPC to yourself.\n");
  302.     exit(1);
  303.     }
  304. #endif NOTDEF
  305.     
  306.  
  307. d103 1
  308. d126 3
  309. a128 3
  310.             inDataBuffer, outDataBuffer, &deltaTime);
  311.     printf("N = %d, Size = %d, Time = %d.%06d\n",
  312.           numEchoes, size, deltaTime.seconds, deltaTime.microseconds);
  313. d135 1
  314. a135 1
  315.             inDataBuffer, outDataBuffer, &deltaTime);
  316. d143 7
  317. a149 5
  318.     for (size = 0; size < maxSize ; size += BYTES_PER_FRAG) {
  319.         DoIt(command, serverID, numEchoes, size);
  320.         for (extra = 400 ; (extra < BYTES_PER_FRAG) &&
  321.             (size+extra < maxSize) ; extra += 400) {
  322.         DoIt(command, serverID, numEchoes, size+extra);
  323. d151 9
  324. d175 1
  325. d180 2
  326. a181 2
  327.         inDataBuffer, outDataBuffer, &deltaTime);
  328.     PrintTime(size, &deltaTime);
  329. d189 1
  330. a189 1
  331. PrintTime(size, timePtr)
  332. d192 1
  333. d194 11
  334. a204 1
  335.     printf("%d\t%d.%06d\n", size, timePtr->seconds, timePtr->microseconds);
  336. d209 2
  337. a210 1
  338. DoTest(command, serverID, numEchoes, size, inDataBuffer, outDataBuffer, timePtr)
  339. d218 1
  340. d222 1
  341. d224 4
  342. d235 14
  343. @
  344.